﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Framework.Common;
using Dal.Entities;

namespace Web.Controllers
{
    public class PreviewController : Controller
    {
        int doctype;
        int docid;
        Framework.Data.IRepository rep;

        public PreviewController()
        {
            rep = Framework.Data.RepositoryFactory.GetRepository();
            //docid
            docid = TypeConvertHelper.StrToInt(System.Web.HttpContext.Current.Request["docid"], 0);
            ViewBag.DocID = docid;
            //doc type
            var doc = rep.GetByKey<Doc>(docid);
            if (doc != null)
            {
                doctype = doc.DocType;
            }
            else
            {
                doctype = Common.DocType();
            }
            ViewBag.DocType = doctype;
        }

        [HttpGet]
        public ActionResult Index()
        {
            return View();
        }

        [HttpGet]
        public ActionResult Doc0(int docid)
        {
            var doccommon = rep.GetByKey<Dal.Entities.DocCommon>(docid);
            return View(doccommon);
        }
        [HttpGet]
        public ActionResult Doc1()
        {
            var Doc1 = rep.GetByKey<Dal.Entities.Doc1>(docid);
            return View(Doc1);
        }
        [HttpGet]
        public ActionResult Doc2()
        {
            var Doc2 = rep.GetByKey<Dal.Entities.Doc2>(docid);
            return View(Doc2);
        }
        [HttpGet]
        public ActionResult Doc3()
        {
            var Doc3 = rep.GetByKey<Dal.Entities.Doc3>(docid);
            return View(Doc3);
        }
        [HttpGet]
        public ActionResult Doc4()
        {
            var Doc4 = rep.GetByKey<Dal.Entities.Doc4>(docid);
            return View(Doc4);
        }
        [HttpGet]
        public ActionResult DocTitle()
        {
            var doc = rep.GetByKey<Dal.Entities.Doc>(docid);
            var doc0 = rep.GetByKey<Dal.Entities.DocCommon>(docid);
            var user = rep.GetByKey<User>(doc.UserID);
            ViewBag.Doc = doc;
            ViewBag.Doc0 = doc0;
            ViewBag.User = user;
            return View();
        }
    }
}
